package com.fancy.learncenter.view;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.fancy.learncenter.adapter.ConditionAdapter;
import com.fancy.learncenter.common.MyApplication;
import com.superservice.lya.R;

import java.util.ArrayList;

/**
 * Created by hyy on 2018/2/25.
 * Explain activity as
 */

public class PopupWindowWriteInfo extends BasedPopupWindow {


    View locationView;

    View popopView;
    View viewParent;


    Activity mContext;


    EditText contact_tv;
    EditText moblie_tv;
    EditText company_tv;
    EditText work_tv;
    TextView confirm;

    public PopupWindowWriteInfo(Activity mContext, View viewParent) {
        super(mContext);
        this.mContext = mContext;
        this.viewParent = viewParent;
        this.locationView = locationView;
        popopView = LayoutInflater.from(MyApplication.context).inflate(R.layout.pupopwinodw_write_info, null);
        initPopupWionw();
    }

    @SuppressLint("WrongConstant")
    private void initPopupWionw() {
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);

        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
//        this.setOutsideTouchable(true);
        this.setFocusable(true);

        this.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        contact_tv = (EditText) popopView.findViewById(R.id.contact_tv);
        moblie_tv = (EditText) popopView.findViewById(R.id.moblie_tv);
        company_tv = (EditText) popopView.findViewById(R.id.company_tv);
        work_tv = (EditText) popopView.findViewById(R.id.work_tv);
        confirm = (TextView) popopView.findViewById(R.id.confrim);


        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                clickCallBack.selecCallBack(contact_tv.getText().toString(), moblie_tv.getText().toString(), company_tv.getText().toString(), work_tv.getText().toString());
            }
        });

        popopView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PopupWindowWriteInfo.this.dismiss();
            }
        });

        this.update();

        this.setContentView(popopView);

    }


    @Override
    public void showPopupWindow() {
        super.showPopupWindow();
        showAsDropDown(viewParent);
    }

    public void setClickCallBack(ClickCallBack clickCallBack) {
        this.clickCallBack = clickCallBack;

//        conditionAdapter.setClickCallBack(new ConditionAdapter.ClickCallBack() {
//            @Override
//            public void clickCallBack(String content) {
//                PopupWindowWriteInfo.this.clickCallBack.selecCallBack(content);
//                PopupWindowWriteInfo.this.dismiss();
//            }
//        });
    }


    @Override
    public void dismiss() {
        super.dismiss();
        if (clickCallBack != null) {
            clickCallBack.cancleCallBack();
        }
    }

    private ClickCallBack clickCallBack;

    public interface ClickCallBack {
        abstract void cancleCallBack();

        abstract void selecCallBack(String contact, String moblie, String work, String company);
    }
}
